package co.com.smart.eagle.client.view.impl.smarttextbutton;

import com.google.gwt.cell.client.ButtonCellBase;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.uibinder.client.UiConstructor;
import com.google.gwt.user.client.ui.Button;

public class SmartCustomButton extends Button {
	
	public interface MyAppearance extends ButtonCellBase.DefaultAppearance.Resources {
		  @Override
		  @Source(value = {ButtonCellBase.DefaultAppearance.Style.DEFAULT_CSS, "textButton.css"})
		  StyleButton buttonCellBaseStyle();
		  
		  public interface StyleButton extends ButtonCellBase.DefaultAppearance.Style { }
	}//End of function...
	
	@UiConstructor
	public SmartCustomButton(String text, ImageResource image) {
		this(text, image, "100px", "30px");
	}//End of function...
	
	public SmartCustomButton(String text, ImageResource image, String width, String height) {
		super();
		String html    = "<div><img src = '"   + 
						 image.getSafeUri().asString() + 
						 //"' height = '" + width + 
						 //"' width  = '" + height + "'"+
						 " />"+
						 "<label>" + 
						 ((text != null)?text:"")      + 
						 "</label></div>";
		setHTML(html);
		setSize(width, height);
	}//End of function...
	
	@Override
	public HandlerRegistration addClickHandler(final ClickHandler handler) {		
		return super.addClickHandler(new ClickHandler() {			
			@Override
			public void onClick(ClickEvent event) {
				if(isEnabled())
				{
					handler.onClick(event);
				}//End of condition...
			}//End of function...
		});	
	}//End of function...
	
}
